	var $box = $(".box"),
			$bg = $('#bg'),
			$bgcolor = $('#bgcolor'),
			$btn = $('#bt'),
			$text = $('#text'),
			$d = $("#d");
			statu = false,
			ox = 0,
			left = 0,
			bgleft = 0,
			lx = 0; //小圆点到窗口左边的距离

			var $start = parseInt($(".J_process_start").html());
			var $end = parseInt($(".J_process_end").html());
			var progressWidth=width=$("#box").width();
	var WIDTH=Math.floor(progressWidth/($end-$start))*($end-$start),BUTTON_PERCENT=5;//扩展的

	var num=parseInt($text.html());
	progressInit(num)


	$(".resetdefaultbtn").click(function(){
		var num =  $box.attr("data-dfrate");
		$(".tube-promo").not(":first").each(function(){
			var nprice = $(this).attr("data-pre") * 1 ;
			var namount = ($(this).siblings("td.tube-amount").text())*1
			$(this).text(nprice.toFixed(2))
			$(this).next("td.tube-sum").text((nprice*namount).toFixed(2))
		})
		var storePrice = $("#J_ActualPaid").attr("data-pre")
		$(".countstore").text(storePrice);
		progressInit(num)
	})
	//初始化
	function progressInit(num) {
//		var $start = parseInt($(".J_process_start").html());
//		var $end = parseInt($(".J_process_end").html());
		var one = Math.floor($("#bg").width() / ($end - $start));
		var xpos = ( parseInt(num) - $start) * one;

		$("#bgcolor").css("width", (xpos) + "px");
		$("#bt").css("left", (xpos) + "px");
		$("#text").css("left", (xpos - 17) + "px").html(num+"%");
		$("#d").val(num);
		$("#dismoney").text($("#dismoney").attr("data-pre"))
		$("#J_ActualPaid").text($("#J_ActualPaid").attr("data-pre"))
	}



		$btn.mousedown(function(e) {
			left = parseInt($btn.css("left"));
			lx = $btn.offset().left;
			ox = e.pageX - left;
			statu = true;
		});

		$(document).mouseup(function() {
			statu = false;
		});

//		基础版
		$box.mousemove(function(e) {
			if (statu) {
//				var $start = parseInt($(".J_process_start").html());
//				var $end = parseInt($(".J_process_end").html());
				var spend = WIDTH / ($end - $start);
				left = e.pageX - ox;
				if (left < 0) {
					left = 0;
				}
				if (left > WIDTH) {
					left = WIDTH;
				}
				$btn.css('left', left);
				$text.css('left', left - 17); //这个17是常量，用作让text元素的left校正到0
				$bgcolor.width(left);
				var percent = parseInt(left / spend) + $start;
				$text.html(percent + '%');
				//$("#cca07").val(percent);
				$d.val(percent)

				rate_default = $box.attr("data-rata-default");
				count = precountic = ($box.attr("data-count"))*1;
				postpage = ($box.attr("postpage"))*1;

				if(percent < rate_default){
					count = count*1 - count*((rate_default - percent)/100);
				} else {
					count = count*1 + count*(( Math.abs(rate_default - percent))/100)*1.17;
				}

				$(".tube-promo").not(":first").each(function(){
					var nprice = $(this).attr("data-pre") * 1 ;
					var namount = ($(this).siblings("td.tube-amount").text())*1;
					if(percent < rate_default){
						nprice = nprice*1 - nprice*((rate_default - percent)/100);
					} else {
						nprice = nprice*1 + nprice*(( Math.abs(rate_default - percent))/100)*1.17;
					}

					$(this).text(nprice.toFixed(2))
					$(this).next("td.tube-sum").text((nprice*namount).toFixed(2))

				})
				console.log(precountic);
				console.log(percent);

				dismoney = precountic * percent / 100;
				$("#dismoney").text(dismoney.toFixed(2));
				$("#J_ActualPaid").text((count+postpage).toFixed(2));
				$(".countstore").text((count+postpage).toFixed(2))

			}
		});

//		扩展的
		$(".ywy_lose_button").click(function (e) {progressMove(e)})
	 	$(".ywy_add_button").click(function (e) {progressMove(e);})

		function progressMove(e){
			BUTTON_PERCENT=5;
			left = parseInt($btn.css("left"));
			var spend = Math.floor(progressWidth / ($end - $start));
			var $nowing=parseInt($text.html());
			var yushu=$nowing%BUTTON_PERCENT;
			var rate_l = $(".J_process_start").attr("data-pre")*1;
			var rate_g = $(".J_process_end").attr("data-pre")*1;
			var now = $("#d").val();

//			修正刻度
			if(e.target.className=='ywy_lose_button' && (now*1 - BUTTON_PERCENT < 0)){
				return;
			}
			if(yushu!=0){
				var posX=spend*($nowing-$start);
				left=posX;
			}

//			减
			if(e.target.className=='ywy_lose_button'){
				if($nowing-$start<5){
					BUTTON_PERCENT=yushu;
				}
				if(left<=0)return ;
			}else{	//加
				if($end-$nowing<5){
					BUTTON_PERCENT=5-yushu;
				}
				if(left>=WIDTH)	return;
			}

			if(e.target.className=='ywy_lose_button'){
				left = left-spend*BUTTON_PERCENT;
			}else{
				left = left+spend*BUTTON_PERCENT;
			}

			$btn.css('left', left);
			$text.css('left', left - 17); //这个17是常量，用作让text元素的left校正到0
			$bgcolor.width(left);
			var percent = Math.ceil(left / spend) + $start;
			$text.html(percent + '%');

			rate_default = $box.attr("data-rata-default");
			count = precountic = ($box.attr("data-count"))*1;
			postpage = ($box.attr("postpage"))*1;

			if(percent < rate_default){
				count = count*1 - count*((rate_default - percent)/100);
			} else {
				count = count*1 + count*(( Math.abs(rate_default - percent))/100)*1.17;
			}

			$(".tube-promo").not(":first").each(function(){
				var nprice = $(this).attr("data-pre") * 1 ;
				var namount = ($(this).siblings("td.tube-amount").text())*1;
				if(percent < rate_default){
					nprice = nprice*1 - nprice*((rate_default - percent)/100);
				} else {
					nprice = nprice*1 + nprice*(( Math.abs(rate_default - percent))/100)*1.17;
				}

				$(this).text(nprice.toFixed(2))
				$(this).next("td.tube-sum").text((nprice*namount).toFixed(2))

			})


			dismoney = precountic * percent / 100;
			$("#dismoney").text(dismoney.toFixed(2));
			$("#J_ActualPaid").text((count+postpage).toFixed(2));
			$(".countstore").text((count+postpage).toFixed(2))
			$("#d").val(percent)
		}




